//
//  YGExpertsTableViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/17.
//

#import "YGExpertsTableViewCell.h"
#import "YGExpertsMsgVIew.h"
#import "YGHomeBLL.h"
#import "YGExpertsMsgCollectionViewCell.h"
#import "YGPatientHomeModel.h"
#import "YGExpertsModel.h"
#import "MBProgressHUD.h"


@interface YGExpertsTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UILabel *expertsLable;
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *expertsArray;




@end
@implementation YGExpertsTableViewCell

#pragma private

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initContraints];
        
    }
    return self;
}

- (void)initView{
    [self addSubview:self.collectionView];
    [self addSubview:self.expertsLable];
    [self addSubview:self.moreBtn];
    _expertsArray= [NSMutableArray array];

}


-(void)clickAction{
         
    
}
//专家信息数据接口
-(void)configureData:(NSArray *)model{
   
    [_expertsArray addObjectsFromArray:model];
    //加完数据立刻刷新
    [self.collectionView reloadData];
}

- (void)initContraints{
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.expertsLable.mas_top).offset(5);
        make.left.mas_equalTo(self.expertsLable.mas_left);
        make.width.mas_equalTo(self.mas_width);
        make.height.mas_equalTo(self.mas_height);
        
        
    }];
    
    [self.expertsLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(15);
            make.left.mas_equalTo(self.mas_left).offset(10);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(20);
       
    }];
    
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.expertsLable.mas_centerY);
            make.left.mas_equalTo(self.mas_right).offset(-50);
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(20);
    }];
    
   
    
}


#pragma  setter

- (UILabel *)expertsLable{
    if (!_expertsLable) {
        _expertsLable = [[UILabel alloc]init];
        _expertsLable.text= @"权威专家";
        _expertsLable.font=[UIFont fontWithName:@"Helvetica-Bold" size:16];
        _expertsLable.textColor=UIColorFromRGB(0x333333);
    }
    return _expertsLable;
}

- (UIButton *)moreBtn{
    if (!_moreBtn) {
        _moreBtn = [[UIButton alloc]init];
        [_moreBtn addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];
        [_moreBtn setTitle:@"更多>" forState:UIControlStateNormal];
        [_moreBtn setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
        _moreBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    }
    return _moreBtn;
}

static NSString *identify=@"YGExpertsMsgCollectionViewCell";

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowlayout=[[UICollectionViewFlowLayout alloc]init];
        [flowlayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,self.contentView.width ,self.contentView.height) collectionViewLayout:flowlayout];
        _collectionView.dataSource=self;
        _collectionView.delegate=self;
        _collectionView.backgroundColor=[UIColor whiteColor];
        [_collectionView registerClass:YGExpertsMsgCollectionViewCell.class forCellWithReuseIdentifier:identify];
        
    }
    return _collectionView;
}

#pragma collectionView delegate


//设置collecview的组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

//设置collecview每组所包含的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _expertsArray.count;
}

//点击collectionview触发事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

//设置每个UIcollectionview的大小
- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout*)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(220, 86);
}

//设置collectioncell的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
        
    YGExpertsMsgCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    YGExpertsModel *model = [self.expertsArray objectAtIndex:indexPath.row];
    //拿到每个对应cell的model，扔进去
    [cell configureData:model];
        return cell;
    }
 

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
